/*
 *  $TEAM_NAME Space Trader
 */
package models;

/**
 * Represents the player in space trader
 * @author bradley
 * @version 1.0
 */
public class Player extends Character {
	/**
	 * field
	 */
	private static Player MY_PLAYER = null;
	
	/**
	 * field
	 */
	private StarSystem location;
    
	/**
	 * field
	 */
	private Ship ship;
	
    /**
     * field
     */
	private static final int STARTING_CREDITS = 5000;
	
	/**
     * field
     */
	private static final int ATTACK_SCALE = 3;

    /**
     * Creates a new player with no specific attributes
     */ 
    private Player() {
        this(null, 0, 0, 0, 0);
    }

    /**
     * Creates a new player with specific attributes
     * @param name - the players name
     * @param fighter - the fighter skill
     * @param pilot - the pilot skill
     * @param trader - the trader skill
     * @param engineer - the engineer skill
     */
    private Player(String name, int fighter, int pilot, int trader, int engineer) {
        super(name, fighter, pilot, trader, engineer);

        // A new player starts with the following
        ship = Ship.gnat();
        if(ship.canAddWeapon(Weapon.pulseLaser())){
        	System.out.print("");
        }

        credits = STARTING_CREDITS;
    }

    /**
     * Gets the player
     * @return the player
     */
    public static Player getPlayer() {
    	if(MY_PLAYER == null){
    		MY_PLAYER = new Player();
    	}
    	
    	return MY_PLAYER;
    }
    
    /**
     * Gets the player with the specific attributes (creates the new player)
     * @param name - the player name
     * @param fighter - fighter skill
     * @param pilot - the pilot skill
     * @param trader - the trader skill
     * @param engineer - the engineer skill
     * @return a player with specified attributes
     */
    public static Player getPlayer(String name, int fighter, 
    		int pilot, int trader, int engineer) {
    	MY_PLAYER = new Player(name, fighter, pilot, trader, engineer);
    	return MY_PLAYER;
    }
    
    /**
     * Gets the players ship
     * @return Ship
     */
    public Ship getShip() {
        return ship;
    }

    /**
     * Sets the players ship
     * @param ship - the ship
     */
    public void setShip(Ship ship) {
        this.ship = ship;
    }

    /**
     * Gets the players current location
     * @return - the location as a solar system
     */
    public StarSystem getLocation() {
        return location;
    }

    /**
     * Sets the players current location
     * @param location - the location
     */
    public void setLocation(StarSystem location) {
        this.location = location;

        setChanged();
        notifyObservers(); 
    }

    /**
     * Gets a string representation of the player
     * @return a string 
     */
    @Override
    public String toString() {
        String out = "Player:";

        out += "\n\tname:\t\t" + this.name;
        out += "\n\tfighter:\t" + this.fighter;
        out += "\n\tpilot:\t\t" + this.pilot;
        out += "\n\ttrader:\t\t" + this.trader;
        out += "\n\tengineer:\t" + this.engineer;

        return out;
    }

    /**
     * attack
     * @return attack
     */
	@Override
	public int attack() {
		final int attackSum = this.fighter + this.ship.attack();
		return attackSum * ATTACK_SCALE;
	}

	/**
	 * defend
	 * @param attack
	 */
	@Override
	public void defend(int attack) {
		this.ship.defend(attack);
	}
}
